package com.itheima.Array.BinarySearch;

/**
 * @Author: Ethan Yankang
 * @Program: code-random-recordings
 * @Date: 2024-07-28 19:25
 **/
public class MinSubArrayLen {
    public int minSubArrayLen(int  target,int[] nums) {

        int len=nums.length;
        int left=0;
        int right=0;
        int sum=0;
        int min=Integer.MIN_VALUE;
        while (right<len){
            sum+=nums[right];
            while (sum>target){
                min=min<(right-left+1)?min:(right-left+1);
                sum-=nums[left++];
            }
            right++;
        }
        return min==Integer.MIN_VALUE?0:min;
    }
}
